package com.qf.java2105.huangchuang.hotel.service.impl;

import com.qf.java2105.huangchuang.hotel.constant.MessageConstant;
import com.qf.java2105.huangchuang.hotel.dao.IUserDao;
import com.qf.java2105.huangchuang.hotel.entity.ResultVO;
import com.qf.java2105.huangchuang.hotel.factory.BeanFactory;
import com.qf.java2105.huangchuang.hotel.pojo.User;
import com.qf.java2105.huangchuang.hotel.service.IUserService;

/**
 * 用户登录业务层实现
 * @author hcvg
 * @version v1.0
 * @date 2021/09/15
 **/
public class UserServiceImpl implements IUserService {
    IUserDao userDao = (IUserDao) BeanFactory.getBean("userDao");
    @Override
    public ResultVO<User> login(String userName) {
        try {
            // 未配置userDao在bean.properties中，java.lang.NullPointerException
            User user = userDao.login(userName);
            if (null != user){
                return ResultVO.ok(MessageConstant.QUERY_USER_SUCCESS, user);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultVO.error(MessageConstant.QUERY_USER_FAILED);

    }
}
